<template>
  <el-card shadow="never" class="user-info-card">
    <template #header>
      <slot name="header"></slot>
    </template>

    <!-- 人员模式布局 -->
    <template v-if="mode === 'member'">
      <el-row class="user-info-header">
        <el-col :span="2" class="avatar-col">
          <ElAvatar :size="100" :src="user.avatar || undefined" shape="square" />
        </el-col>
        <el-col :span="22" class="basic-info-col">
          <el-descriptions :column="2" class="basic-info-descriptions">
            <el-descriptions-item>
              <template #label>
                <descriptions-item-label icon="ep:user" label="姓名" />
              </template>
              {{ user.name || '-' }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template #label>
                <descriptions-item-label icon="fa:mars-double" label="性别" />
              </template>
              <dict-tag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="user.sex" />
            </el-descriptions-item>
            <el-descriptions-item v-if="user.foreigner === 2">
              <template #label>
                <descriptions-item-label icon="ep:user" label="身份证号" />
              </template>
              {{ user.idcard || '-' }}
            </el-descriptions-item>
            <el-descriptions-item v-if="user.foreigner === 1">
              <template #label>
                <descriptions-item-label icon="ep:user" label="护照号" />
              </template>
              {{ user.passportNumber || '-' }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template #label>
                <descriptions-item-label icon="ep:phone" label="手机号" />
              </template>
              {{ user.phoneNumber || '-' }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template #label>
                <descriptions-item-label icon="ep:location" label="户籍地" />
              </template>
              {{ user.birthPlace || '-' }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template #label>
                <descriptions-item-label icon="ep:location" label="居住地" />
              </template>
              {{ user.liveAddress || '-' }}
            </el-descriptions-item>


            <el-descriptions-item>
              <template #label>
                <descriptions-item-label icon="ep:location" label="常去地" />
              </template>
              {{ user.frequentAddress || '-' }}
              <span v-if="user.appearanceCount">({{ user.appearanceCount }}次)</span>
            </el-descriptions-item>
            <el-descriptions-item>
              <template #label>
                <descriptions-item-label icon="ep:location" label="最后地" />
              </template>
              {{ user.lastLocation || '-' }}({{ user.lastLocationTime || '-' }})
            </el-descriptions-item>
          </el-descriptions>
        </el-col>
      </el-row>
    </template>

  </el-card>
</template>

<script lang="ts" setup>
import { DICT_TYPE } from '@/utils/dict'
import * as UserApi from '@/api/member/user'
import { DescriptionsItemLabel } from '@/components/Descriptions/index'
import { ElAvatar } from 'element-plus'

withDefaults(defineProps<{
  user: UserApi.UserVO;
  mode?: string;
  column?: number;
}>(), {
  mode: 'member',
  column: 2
})
</script>

<style lang="scss" scoped>
.user-info-card {
  border-radius: 8px;
  overflow: hidden;
  transition: all 0.3s ease;

  &:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  }
}

.user-info-header {
  border-bottom: 1px solid #f2f3f5;
  align-items: center;
}

.avatar-col {
  display: flex;
  justify-content: center;
  padding: 0 16px;
}

.basic-info-col {
  padding: 0 16px;
}

.basic-info-descriptions {
  ::v-deep .el-descriptions__cell {
    padding: 10px 12px;

    .el-descriptions__label {
      font-weight: 500;
      color: #606266;
    }
  }
}

// 活动信息样式
.el-divider {
  margin: 16px 0;
}

.activity-info-descriptions {
  margin-top: 8px;
}

// 通用描述列表样式
::v-deep(.custom-descriptions.el-descriptions--border) {
  .el-descriptions__row {
    border-bottom: 1px solid #f2f3f5;
    &:last-child {
      border-bottom: none;
    }
  }

  .el-descriptions__cell {
    border-right: 1px solid #f2f3f5;
    padding: 12px;

    .el-descriptions__label {
      font-weight: 500;
      color: #606266;
    }
  }

  // 列边框处理
  &.columns-2 {
    .el-descriptions__cell:nth-child(2n) {
      border-right: none;
    }
  }

  &.columns-3 {
    .el-descriptions__cell:nth-child(3n) {
      border-right: none;
    }
  }

  &.columns-1 {
    .el-descriptions__cell {
      border-right: none;
    }
  }
}

// 长文本处理
.long-text-container {
  max-width: 100%;
  line-height: 1.6;
  word-break: break-word;
}

// 客服模式样式
.kefu-header {
  display: flex;
  justify-content: center;
  padding: 16px 0;
}

::v-deep(.kefu-descriptions) {
  .el-descriptions__cell {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid #f2f3f5;
    &:last-child {
      border-bottom: none;
    }

    .el-descriptions__label {
      width: 120px;
      display: block;
      text-align: left;
      font-weight: 500;
      color: #606266;
    }

    .el-descriptions__content {
      flex: 1;
      text-align: end;
      word-break: break-word;
    }
  }
}

// 响应式调整
@media (max-width: 768px) {
  .user-info-header {
    flex-direction: column;
  }

  .avatar-col, .basic-info-col {
    width: 100%;
    padding: 8px 0;
  }

  .basic-info-descriptions,
  .activity-info-descriptions {
    ::v-deep {
      .el-descriptions__column {
        flex: 0 0 100% !important;
        width: 100% !important;
      }

      .el-descriptions__cell {
        border-right: none !important;
        width: 100% !important;
      }
    }
  }
}

// 活动信息描述列表样式（重点设置）
:deep(.basic-info-descriptions .el-descriptions__cell) {
  // 只保留底部内边距
  padding: 0 0 12px;
}
</style>
